//
//  XMMineHeaderView.m
//  XMJJ_zml
//
//  Created by apple on 2025/5/10.
//

#import "XMCityView.h"
#import "XMPropertyView.h"
#import "XMUserInfoModel.h"
@interface XMCityView ()

@property (nonatomic, strong) UIImageView *avatarImgView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *userIdLabel;
@property (nonatomic, strong) UIButton *QRCodeBtn;
@property (nonatomic, strong) UILabel *authenLabel;
@property (nonatomic, strong) UILabel *briefIntroucLabel;

@property (nonatomic, strong) UILabel *praiseNumLabel; //获赞
@property (nonatomic, strong) UILabel *followEachOtherNumLabel; //互关
@property (nonatomic, strong) UILabel *attentionNumLabel;  //关注
@property (nonatomic, strong) UILabel *fansNumLabel;  //粉丝


@property (nonatomic, strong) UILabel *city; // 城市
@property (nonatomic, strong) UILabel *privide; //省份
@property (nonatomic, strong) UILabel *address;  //具体地址

@property (nonatomic, strong) UIImageView * shopp;  //橱窗图表

@property (nonatomic, strong) UILabel * showcase;  //橱窗

@property (nonatomic, strong) UILabel *produce;  //产品


@end

@implementation XMCityView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self creatUI];
        self.userInteractionEnabled = YES;
    }
    return self;
}

- (void)creatUI {
    UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, KScaleWidth(612.0))];
    [titleView setGradientLayerWithLocations:@[@(0), @(1.0)] colors:@[(__bridge id)kColorHEX(0x7A6A3F).CGColor, (__bridge id)kColorHEX(0x817A66).CGColor] startPoint:CGPointMake(0.5, 0) endPoint:CGPointMake(0.5, 1)];
    [self addSubview:titleView];
    self.clipsToBounds = YES;
    
    [self addSubview:self.avatarImgView];
    [self addSubview:self.city];
    [self addSubview:self.privide];
    [self addSubview:self.address];
    [self addSubview:self.nameLabel];
    [self addSubview:self.userIdLabel];
    [self addSubview:self.briefIntroucLabel];
    [self addSubview:self.shopp];
    [self addSubview:self.showcase];
    [self addSubview:self.produce];


    NSArray *titleArr = @[@"获赞", @"互关", @"粉丝"];
    for (int i = 0; i < titleArr.count; i ++) {
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake((KScaleWidth(24.0) + KScaleWidth(28.0))*i, _briefIntroucLabel.maxY + KScaleWidth(28.0), KScaleWidth(24.0) + KScaleWidth(28.0), KScaleWidth(20.0)) font:KFontSize(14.0) textColor:kColorHEXA(0xffffff, 0.84) textAlignment:NSTextAlignmentCenter];
        titleLabel.text = titleArr[i];
        [self addSubview:titleLabel];
    }
    [self addSubview:self.praiseNumLabel];
    [self addSubview:self.followEachOtherNumLabel];
//    [self addSubview:self.attentionNumLabel];
    [self addSubview:self.fansNumLabel];
    
    
    
    UIButton *editHomePageBtn = [UIButton buttonWithType:UIButtonTypeCustom font:KBoldFontSize(15.0) frame:CGRectMake(self.width - KScaleWidth(16.0) - KScaleWidth(29.0) - KScaleWidth(86.0), _briefIntroucLabel.maxY + KScaleWidth(10.0), KScaleWidth(56.0), KScaleWidth(32.0)) title:@"关注" titleColor:kColorHEX(0xffffff)];
    editHomePageBtn.centerY = self.shopp.centerY;
    [editHomePageBtn setRadius:editHomePageBtn.height/2 borderColor:kColorHEX(0xffffff) borderWidth:1];
    editHomePageBtn.backgroundColor = kColorHEXA(0xffffff, 0.13);
    [editHomePageBtn addTarget:self action:@selector(homePageEditAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:editHomePageBtn];
    
    
//    UIButton * sendMessageBtn = [UIButton buttonWithType:UIButtonTypeCustom font:KBoldFontSize(15.0) frame:CGRectMake(editHomePageBtn.maxX + KScaleWidth(10.0) , _briefIntroucLabel.maxY + KScaleWidth(10.0), KScaleWidth(86.0), KScaleWidth(32.0)) title:@"" titleColor:kColorHEX(0xffffff)];
    UIImage * msagegeImage = [UIImage imageNamed:@"message"] ;
    UIButton * sendMessageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    sendMessageBtn.frame  = CGRectMake(editHomePageBtn.maxX + KScaleWidth(15.0) , _briefIntroucLabel.maxY + KScaleWidth(10.0), msagegeImage.size.width, msagegeImage.size.height);
    [sendMessageBtn setBackgroundImage:msagegeImage forState:UIControlStateNormal];
    sendMessageBtn.centerY = self.shopp.centerY;
    [sendMessageBtn setRadius:sendMessageBtn.height/2 borderColor:kColorHEX(0xffffff) borderWidth:1];
    sendMessageBtn.backgroundColor = kColorHEXA(0xffffff, 0.13);
    [sendMessageBtn addTarget:self action:@selector(sendmessage:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:sendMessageBtn];
    self.showcase.userInteractionEnabled = YES;
    UITapGestureRecognizer * tapGesures = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(goShop)];
    [self.showcase addGestureRecognizer:tapGesures];
   
}

- (void)resetInfoWithUserInfoModel:(XMUserInfoModel *)userInfoModel {
    XMUserModel *userModel = [[XMUserManager shareInstance] getUser];
    _nameLabel.text = userModel.nickName;
//    _userIdLabel.text = [NSString stringWithFormat:@"ID: %@", userInfoModel.idNo];
    
//    _praiseNumLabel.text = userInfoModel.likeCount;
//    _followEachOtherNumLabel.text = userInfoModel.huguanCount;
//    _attentionNumLabel.text = userInfoModel.attentionCount;
//    _fansNumLabel.text = userInfoModel.fensi;
}

- (void)goShop {
    if (self.delegate && [self.delegate respondsToSelector:@selector(goShop)]) {
         [self.delegate goShop];
     }
}
- (void)homePageEditAction:(UIButton *)button {
    if (self.delegate && [self.delegate respondsToSelector:@selector(attionAction)]) {
         [self.delegate attionAction];
     }
}
- (void)sendmessage:(UIButton *)button {
    if (self.delegate && [self.delegate respondsToSelector:@selector(sendMessageAction)]) {
         [self.delegate sendMessageAction];
     }
}


#pragma mark - Init
- (UIImageView *)avatarImgView {
    if (!_avatarImgView) {
        _avatarImgView = [[UIImageView alloc] initWithFrame:CGRectMake(KScaleWidth(14.0), KScaleWidth(103.0), KScaleWidth(78.0), KScaleWidth(78.0))];
        [_avatarImgView setCornerRadius:_avatarImgView.height/2];
        _avatarImgView.image = ImageNamed(@"mine_avatar_icon");
    }
    return _avatarImgView;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(KScaleWidth(107.0), KScaleWidth(112.0), self.width - KScaleWidth(107.0), KScaleWidth(35.0)) font:KBoldFontSize(18.0) textColor:kColorHEX(0xffffff)];
    }
    return _nameLabel;
}

- (UILabel *)userIdLabel {
    if (!_userIdLabel) {
        _userIdLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.nameLabel.x, _nameLabel.maxY, _nameLabel.width, KScaleWidth(17.0)) font:KFontSize(12.0) textColor:kColorHEXA(0xffffff, 0.6)];
    }
    return _userIdLabel;
}

//简介
- (UILabel *)city {
    if (!_city) {
        _city = [[UILabel alloc] initWithFrame:CGRectMake(KScaleWidth(13.0), self.avatarImgView.maxY + KScaleWidth(15.0),  KScaleWidth(50.0), KScaleWidth(30.0)) font:KFontSize(14.0) textColor:kColorHEXA(0xffffff, 0.84)];
        _city.text = @"北京市";
    }
    return _city;
}


//简介
- (UILabel *)privide {
    if (!_privide) {
        _privide = [[UILabel alloc] initWithFrame:CGRectMake(self.city.maxX, self.city.y,KScaleWidth(50.0), KScaleWidth(30.0)) font:KFontSize(14.0) textColor:kColorHEXA(0xffffff, 0.84)];
        _privide.text = @"河北省";
    }
    return _privide;
}



//简介
- (UILabel *)address {
    if (!_address) {
        _address = [[UILabel alloc] initWithFrame:CGRectMake(self.privide.maxX, self.privide.y, KScaleWidth(100), KScaleWidth(30.0)) font:KFontSize(14.0) textColor:kColorHEXA(0xffffff, 0.84)];
        _address.text = @"保定学院";
    }
    return _address;
}

//简介
- (UILabel *)briefIntroucLabel {
    if (!_briefIntroucLabel) {
        _briefIntroucLabel = [[UILabel alloc] initWithFrame:CGRectMake(KScaleWidth(13.0), self.address.maxY, self.width - KScaleWidth(13.0), KScaleWidth(30.0)) font:KFontSize(14.0) textColor:kColorHEXA(0xffffff, 0.84)];
        _briefIntroucLabel.text = @"点击这里填写简介";
    }
    return _briefIntroucLabel;
}

- (UILabel *)praiseNumLabel {
    if (!_praiseNumLabel) {
        _praiseNumLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, self.briefIntroucLabel.maxY, KScaleWidth(24.0) + KScaleWidth(28.0), KScaleWidth(25.0)) font:KBoldFontSize(18.0) textColor:kColorHEX(0xffffff) textAlignment:NSTextAlignmentCenter];
        _praiseNumLabel.text = @"--";
    }
    return _praiseNumLabel;
}

- (UILabel *)followEachOtherNumLabel {
    if (!_followEachOtherNumLabel) {
        _followEachOtherNumLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.praiseNumLabel.maxX, _praiseNumLabel.y, _praiseNumLabel.width, _praiseNumLabel.height) font:KBoldFontSize(18.0) textColor:kColorHEX(0xffffff) textAlignment:NSTextAlignmentCenter];
        _followEachOtherNumLabel.text = @"--";
    }
    return _followEachOtherNumLabel;
}

//- (UILabel *)attentionNumLabel {
//    if (!_attentionNumLabel) {
//        _attentionNumLabel = [[UILabel alloc] initWithFrame:self.followEachOtherNumLabel.frame font:KBoldFontSize(18.0) textColor:kColorHEX(0xffffff) textAlignment:NSTextAlignmentCenter];
//        _attentionNumLabel.x = _followEachOtherNumLabel.maxX;
//        _attentionNumLabel.text = @"--";
//    }
//    return _attentionNumLabel;
//}

- (UILabel *)fansNumLabel {
    if (!_fansNumLabel) {
        _fansNumLabel = [[UILabel alloc] initWithFrame:self.followEachOtherNumLabel.frame font:KBoldFontSize(18.0) textColor:kColorHEX(0xffffff) textAlignment:NSTextAlignmentCenter];
        _fansNumLabel.x = _followEachOtherNumLabel.maxX;
        _fansNumLabel.text = @"--";
    }
    return _fansNumLabel;
}




- (UIImageView *)shopp {
    if (!_shopp) {
        UIImage * image = [UIImage imageNamed:@"shop"];
        _shopp = [[UIImageView alloc]initWithFrame:CGRectMake(self.city.x, self.followEachOtherNumLabel.maxY+KScaleWidth(45.0), image.size.width, image.size.height)];
//        _shopp = [[UIImageView alloc] initWithFrame:CGRectMake(KScaleWidth(13.0), _praiseNumLabel.y, _praiseNumLabel.width, _praiseNumLabel.height) font:KBoldFontSize(18.0) textColor:kColorHEX(0xffffff) textAlignment:NSTextAlignmentCenter];
        _shopp.x = _city.x;
        _shopp.image = image;
    }
    return _shopp;
}

- (UILabel *)showcase {
    if (!_showcase) {
        _showcase = [[UILabel alloc] initWithFrame:CGRectMake(self.shopp.x+self.privide.width + 10, self.shopp.y + 10, KScaleWidth(75.0), KScaleWidth(35.0)) font:KBoldFontSize(16.0) textColor:kColorHEX(0xffffff) textAlignment:NSTextAlignmentCenter];
        _showcase.x = self.shopp.x + self.shopp.width + 10;
        _showcase.userInteractionEnabled = YES;
        _showcase.text = @"他的橱窗";
    }
    return _showcase;
}

- (UILabel *)produce {
    if (!_produce) {
        _produce = [[UILabel alloc] initWithFrame:CGRectMake(self.showcase.x, self.showcase.maxY - 30, KScaleWidth(75.0), KScaleWidth(75.0)) font:KBoldFontSize(15.0) textColor:kColorHEX(0xffffff) textAlignment:NSTextAlignmentCenter];
        _produce.x = self.showcase.x;
        _produce.text = @"23个产品";
    }
    return _produce;
}
@end
